package com.niit.cms.service.impl;

import com.niit.cms.entity.Progress;
import com.niit.cms.dao.ProgressDao;
import com.niit.cms.service.ProgressService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Progress)表服务实现类
 *
 * @author makejava
 * @since 2022-06-28 10:55:40
 */
@Service("progressService")
public class ProgressServiceImpl implements ProgressService {
    @Resource
    private ProgressDao progressDao;

    /**
     * 通过ID查询单条数据
     *
     * @param uid 主键
     * @return 实例对象
     */
    @Override
    public Progress queryById(Integer uid, Integer vid, Integer courseId) {
        return this.progressDao.queryById(uid, vid, courseId);
    }

    /**
     * 分页查询
     *
     * @param progress    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<Progress> queryByPage(Progress progress, PageRequest pageRequest) {
        long total = this.progressDao.count(progress);
        return new PageImpl<>(this.progressDao.queryAllByLimit(progress, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param progress 实例对象
     * @return 实例对象
     */
    @Override
    public Progress insert(Progress progress) {
        this.progressDao.insert(progress);
        return progress;
    }

    /**
     * 修改数据
     *
     * @param progress 实例对象
     * @return 实例对象
     */
    @Override
    public Progress update(Progress progress) {
        this.progressDao.update(progress);
        return this.queryById(progress.getUid(), progress.getVid(), progress.getCourseId());
    }

    /**
     * 通过主键删除数据
     *
     * @param uid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer uid, Integer vid, Integer courseId) {
        return this.progressDao.deleteById(uid, vid, courseId) > 0;
    }
    /**
     * 通过uid查询数据
     *
     * @param uid
     * @return 实例对象
     */
    @Override
    public List<Progress> queryListByUid(Integer uid) {
        return progressDao.queryListByUid(uid);
    }
    /**
     * 通过courseId查询数据
     *
     * @param courseId
     * @return 实例对象
     */
    @Override
    public List<Progress> queryListByCourseIdState(Integer courseId, int state) {
        return progressDao.queryListByCourseIdState(courseId, state);
    }
    /**
     * 通过courseId查询数据
     *
     * @param courseId
     * @return 实例对象
     */
    @Override
    public List<Progress> queryListByCourseId(Integer courseId) {
        return progressDao.queryListByCourseId(courseId);
    }
}
